<?php if(!defined('PHPOK_SET')){die('<h3>Error...</h3>');}?><?php $APP->tpl->p("header","","0");?>
<script type="text/javascript">
var input_id = "<?php echo $input_id;?>";
var input_view = "<?php echo $input_view;?>";

function clickpic(id)
{
	//读取原有表单中的数据
	var vid = parent.getid(input_id).value;
	if(vid)
	{
		var n_vid = join_str(vid,id);
	}
	else
	{
		var n_vid = id;
	}
	//重新写入
	parent.getid(input_id).value = n_vid;
	//预览数据
	view_picture(n_vid);
}

function view_picture(n_vid)
{
	if(!n_vid || n_vid =="" || n_vid == "undefined")
	{
		parent.getid(input_id).value = "";
		parent.getid(input_view).innerHTML = "<img src='./app/admin/view/images/nopic.gif' />";
		getid("p_show_view").style.display = "none";
		getid("p_show_submit").style.display = "none";
		return true;
	}
	var url = "<?php echo site_url('open,ajax_preview_img');?>idstring="+n_vid;
	get_ajax(url,view_picture_ajax);
}

function view_picture_ajax(msg)
{
	if(msg == "empty")
	{
		view_picture("");
		return true;
	}
	var array = $.evalJSON(msg);
	//通过Ajax获取图片列表
	var p_html = '<table><tr>';
	var v_html = '<table width="100%"><tr>';
	for(var i=0;i<array.length;i++)
	{
		var tmp_i = i+1;
		var srcurl = array[i]["url"];
		if(!srcurl || srcurl == "" || srcurl == "undefined")
		{
			srcurl = "./app/admin/view/images/nopic.gif";
		}
		p_html += '<td><img src="'+srcurl+'" width="80px" height="80px" class="hand" onclick="phpjs_preview(\''+array[i]["id"]+'\')" /></td>';
		v_html += "<td><div align='center'><img src='"+srcurl+"' width='80px' height='80px' /></div><div style='padding-top:3px;text-align:center;'><input type='checkbox' value='"+array[i]["id"]+"'>";
		v_html += " <input type='text' style='width:35px;' id='sort_"+array[i]["id"]+"' value='"+tmp_i+"'></div></td>";
		if(tmp_i%8 == "")
		{
			p_html += "</tr><tr>";
		}
		if(tmp_i%5 == "")
		{
			v_html += "</tr><tr>";
		}
	}
	p_html += "</tr></table>";
	v_html += "</tr></table>";
	//预览
	parent.getid(input_view).innerHTML = p_html;
	getid("p_show_view").style.display = "";
	getid("p_show_view").innerHTML = v_html;
	getid("p_show_submit").style.display = "";
	return true;
}

//更新排序
function sort_order()
{
	var id = join_checkbox("p_show_view","all");//读取全部
	if(!id)
	{
		alert("找不到相关信息排序");
		return false;
	}
	var taxis = new Array();
	var id_list = id.split(",");
	var id_len = id_list.length;
	var m = 1;
	for(var i=0;i<id_len;i++)
	{
		var tt = document.getElementById("sort_"+id_list[i]);
		if(tt)
		{
			taxis[m] = "taxis["+id_list[i]+"]="+tt.value;
			m++;
		}
	}
	var taxis_string = taxis.join("&");
	if(!taxis_string)
	{
		hiAlert("没有找到排序信息~");
		return false;
	}
	//执行排序操作
	var url = "<?php echo site_url('open,sort_order');?>"+taxis_string;
	var msgid = get_ajax(url);//执行操作
	if(msgid != "error")
	{
		parent.getid(input_id).value = msgid;
		view_picture(msgid);
		return true;
	}
	else
	{
		alert("排序操作出错，请检查");
		return false;
	}
}

//删除图片操作
function del_selected()
{
	var id = join_checkbox("p_show_view","all");//读取全部
	if(!id)
	{
		alert("找不到相关信息");
		return false;
	}
	//读取已选中的
	var del_id = join_checkbox("p_show_view","checked");
	if(!del_id)
	{
		alert("请选中要删除的图片");
		return false;
	}
	var n_id = new Array();
	var id_list = id.split(",");
	var del_id_list = del_id.split(",");
	var id_len = id_list.length;
	var del_len = del_id_list.length;
	var m = 0;
	for(var i = 0;i<id_len;i++)
	{
		var myid = id_list[i];
		for(var n=0;n<del_len;n++)
		{
			if(myid == del_id_list[n])
			{
				myid = "delete";
			}
		}
		if(myid && myid != "delete")
		{
			n_id[m] = myid;
			m++;
		}
	}
	var new_id = n_id.join(",");
	if(new_id)
	{
		parent.getid(input_id).value = new_id;
	}
	view_picture(new_id);
	return true;
}
</script>
<?php $APP->tpl->p("swfupload","","0");?>
<div class="main">
<div id="p_show_view" style="display:none;"></div>
<div id="p_show_submit" style="display:none;text-align:left;padding:2px auto;">&nbsp;<input type="button" value="更新排序" class="btn3" onclick="sort_order();"> <input type="button" value="删除" class="btn2" onclick="del_selected()"> <input type="button" value="提交" onclick="parent.Layer.over();" class="btn2"> 排序值越小越往前靠，不能重复，选择要删除的图片再执行操作。</div>
<table width="100%" style="layout:fixed;">
<tr>
	<?php $_i=0;$rslist=(is_array($rslist))?$rslist:array();foreach($rslist AS  $key=>$value){$_i++; ?>
	<td style="text-align:center;padding-top:5px;"><img src="<?php echo $value[thumb];?>" width="80px" height="80px" id="thumb_<?php echo $value[id];?>" class="hand" onclick="clickpic('<?php echo $value[id];?>');" title="上传时间：<?php echo date('Y-m-d H:i:s',$value[postdate]);?>&#13;&#10;文件名称：<?php echo $value[title] ? $value[title] : basename($value[filename]);?>" /></td>
	<?php if($_i%5===0){echo '</tr><tr>';}?>
	<?php } ?>
</tr>
</table>
</div>
<?php if($pagelist){?><div class="table"><?php echo $pagelist;?></div><?php } ?>
<script type="text/javascript">
var t_id = parent.getid(input_id).value;
if(t_id)
{
	view_picture(t_id);
}
</script>

<?php $APP->tpl->p("footer_open","","0");?>